﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseDao
{
    public class BaseService<T>
        where T : TBaseModel
    {
        private IBaseProvider<T> _Provider = new MemoryBaseProvider<T>();

        protected virtual IBaseProvider<T> Provider { get { return _Provider; } }

        /// <summary>
        /// 增加一个数据实例
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual bool Add(T model)
        {
            return Provider.Add(model);
        }

        /// <summary>
        /// 根据Id删除一个数据实例
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual bool RemoveById(long id)
        {
            return Provider.RemoveById(id);
        }

        /// <summary>
        /// 更新一个数据实例
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual bool Update(T model)
        {
            return Provider.Update(model);
        }

        /// <summary>
        /// 根据Id获取一个数据实例
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual T GetItemById(long id)
        {
            return Provider.GetItemById(id);
        }

        /// <summary>
        /// 获取全部在维护的数据实例
        /// </summary>
        /// <returns></returns>
        public virtual List<T> GetAll()
        {
            return Provider.GetAll();
        }

        /// <summary>
        /// 根据Ids获取列表数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public virtual List<T> GetListByIds(List<long> ids)
        {
            return Provider.GetListByIds(ids);
        }
    }
}
